<template>
  <div class="mod-purchaseannouncement__purchaseannouncement">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item>
        <el-input v-model="state.dataForm.purchaseProjectName" placeholder="项目名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="state.dataForm.purchaseProjectCode" placeholder="项目编号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="state.getDataList()">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('purchaseannouncement:purchaseannouncement:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-form-item>
<!--      <el-form-item>-->
<!--        <el-button v-if="state.hasPermission('purchaseannouncement:purchaseannouncement:delete')" type="danger" @click="state.deleteHandle()">删除</el-button>-->
<!--      </el-form-item>-->
<!--      <el-form-item>-->
<!--        <el-button v-if="state.hasPermission('purchaseannouncement:purchaseannouncement:export')" type="info" @click="state.exportHandle()">导出</el-button>-->
<!--      </el-form-item>-->
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
              <el-table-column prop="purchaseProjectName" label="项目名称" header-align="center" align="center"></el-table-column>
              <el-table-column prop="purchaseProjectCode" label="项目编号" header-align="center" align="center"></el-table-column>
              <el-table-column prop="announcementName" label="公告名称" header-align="center" align="center"></el-table-column>
              <el-table-column prop="announcementNature" label="公告性质" header-align="center" align="center">
                <template v-slot="scope">
                  {{ state.getDictLabel("announcement_nature", scope.row.announcementNature) }}
                </template>
              </el-table-column>
              <el-table-column prop="applyStartTime" label="报名开始时间" header-align="center" align="center"></el-table-column>
              <el-table-column prop="applyEndTime" label="报名结束时间" header-align="center" align="center"></el-table-column>
              <el-table-column prop="isPublish" label="公告状态" header-align="center" align="center">
                <template v-slot="scope">
                  {{ state.getDictLabel("announcement_status", scope.row.isPublish) }}
                </template>
              </el-table-column>
              <el-table-column prop="publishTime" label="公告发布时间" header-align="center" align="center"></el-table-column>
<!--              <el-table-column prop="createUser" label="项目创建人" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="createTime" label="项目创建时间，格式：YYYY-MM-DD HH:MM:SS" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="updateUser" label="最后更新人" header-align="center" align="center"></el-table-column>-->
<!--              <el-table-column prop="updateTime" label="最后更新时间，格式：YYYY-MM-DD HH:MM:SS" header-align="center" align="center"></el-table-column>-->
            <el-table-column label="操作" fixed="right" header-align="center" align="center" width="200">
        <template v-slot="scope">
          <el-button type="primary" link @click="detailHandle(scope.row.purchaseAnnouncementId)">详情</el-button>
          <el-button v-if="state.hasPermission('purchaseannouncement:purchaseannouncement:update')" type="primary" link @click="addOrUpdateHandle(scope.row.purchaseAnnouncementId)">更正</el-button>
<!--          <el-button v-if="state.hasPermission('purchaseannouncement:purchaseannouncement:delete')" type="primary" link @click="state.deleteHandle(scope.row.purchaseAnnouncementId)">删除</el-button>-->
          <el-button v-if="state.hasPermission('purchaseannouncement:purchaseannouncement:releaseAnnouncement') && scope.row.isPublish == '1'" type="primary" link @click="releaseAnnouncementHandle(scope.row.purchaseAnnouncementId)">发布</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit" :total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="state.pageSizeChangeHandle" @current-change="state.pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update ref="addOrUpdateRef" @refreshDataList="state.getDataList">确定</add-or-update>
    <detail ref="detailRef" @refreshDataList="state.getDataList">确定</detail>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import { reactive, ref, toRefs } from "vue";
import AddOrUpdate from "./purchaseannouncement-add-or-update.vue";
import detail from "./purchaseannouncement-detail.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { IObject } from "@/types/interface";
import baseService from "@/service/baseService";

const view = reactive({
  deleteIsBatch: true,
  getDataListURL: "/purchaseannouncement/purchaseannouncement/page",
  getDataListIsPage: true,
  exportURL: "/purchaseannouncement/purchaseannouncement/export",
  deleteURL: "/purchaseannouncement/purchaseannouncement"
});

const state = reactive({ ...useView(view), ...toRefs(view) });

const addOrUpdateRef = ref();
const addOrUpdateHandle = (id?: number) => {
  addOrUpdateRef.value.init(id);
};

const detailRef = ref();
const detailHandle = (id?: number) => {
  detailRef.value.init(id);
};

// 发布公告
const releaseAnnouncementHandle = (id?: string) => {
  ElMessageBox.confirm("是否确定发布?", "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning"
    }).then(() => {
     console.log("==========---" + id);
        baseService.get("/purchaseannouncement/purchaseannouncement/releaseAnnouncement?id="+ id).then((res) => {
          ElMessage.success({
            message: "成功",
            duration: 500,
            onClose: () => {
              state.getDataList();
            }
          });
        });
      })
      .catch(() => {
        console.log("12222222222222222---" + id)
      });
  };
</script>
